<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
       /* .main{height: 100px}*/
    </style>
</head>
<body>
<div class="main">
<form action="vote.php" method="post">
    <input name="code" id="code"><img src="code.php" width="44" height="18">
    <input type="button" value="提交" onclick="go(<?php echo $_GET['carID'];?>)">
</form>
</div>
<script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
    $(function (){
        console.log($('html').height())
        $(".main").css('height',$('html').height())
    })
    function go(carID){
        let code = $("#code").val().trim();
        if(code.length === 0){
            alert('验证码必填');
        }
        else{
            ajax(carID,code);
        }
    }
    function ajax(carID,code){
        $.ajax({
            url:'postVote.php',
            type:'post',
            dataType:'json',
            data:{
                code:code,
                carID:carID
            },
            success:function (d){
                //console.log(d);
                if(d.code == 200){
                    let lastNum = parseInt($("#car" + carID,parent.document).text());
                    $("#car" + carID,parent.document).text(lastNum + 1);
                    alert('投票成功');
                }
                else{
                    alert(d.msg);
                }
                //关闭弹窗
                window.parent.close();
            },
            error:function (d1,d2,d3){
                console.log(d1);
                console.log(d2);
                console.log(d3);
                //关闭弹窗
                window.parent.close();
            }
        })
        //516213
    }
</script>
</body>
</html>